using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using MonitorPlatform.Data.Entities;

namespace MonitorPlatform.Data.Configurations
{
    public class PerformanceMetricConfiguration : IEntityTypeConfiguration<PerformanceMetric>
    {
        public void Configure(EntityTypeBuilder<PerformanceMetric> builder)
        {
            // Additional configuration for PerformanceMetric
            // This is useful for complex configurations that we don't want in OnModelCreating

            // Example: Configure column store index (SQL Server specific)
            // builder.HasAnnotation("SqlServer:ColumnStoreIndex", true);

            // Example: Configure partitioning (if needed)
            // builder.HasAnnotation("SqlServer:PartitionFunction", "PF_Timestamp");
            // builder.HasAnnotation("SqlServer:PartitionScheme", "PS_Timestamp");

            // Configure precision for decimal fields
            builder.Property(e => e.FirstContentfulPaint)
                .HasPrecision(18, 3);
            
            builder.Property(e => e.LargestContentfulPaint)
                .HasPrecision(18, 3);
            
            builder.Property(e => e.FirstInputDelay)
                .HasPrecision(18, 3);
            
            builder.Property(e => e.CumulativeLayoutShift)
                .HasPrecision(18, 6);
            
            builder.Property(e => e.TimeToFirstByte)
                .HasPrecision(18, 3);

            // Configure computed columns for performance analysis
            // builder.Property(e => e.PerformanceScore)
            //     .HasComputedColumnSql("CASE WHEN [LargestContentfulPaint] <= 2500 THEN 100 ELSE 0 END");

            // Configure default values
            builder.Property(e => e.Timestamp)
                .HasDefaultValueSql("GETUTCDATE()");
        }
    }
} 